<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
    <head>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="stylesheet" href="layui/css/layui.css" media="all"> <!-- 适应所有设备 -->
		<style type="text/css">
		</style>
	</head>
	<% String nowDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); %>
	<body>
		<table class="layui-table" id="feedBackSet" lay-filter="feedBackSet">
		<caption style="color:#d71345">代理返还比例设置</caption>
		</table>
		
		<script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
		<script type="text/html" id="agent0">
           <span>{{ d.agent0 }}点</span>
        </script>
        <script type="text/html" id="agent1">
           <span>{{ d.agent1 }}点</span>
        </script>
        <script type="text/html" id="agent2">
           <span>{{ d.agent2 }}点</span>
        </script>
        <script type="text/html" id="platformAgent">
           {{# d.platformAgent = 100 - (d.agent0 + d.agent1 + d.agent2) }}
           <span>{{ d.platformAgent }}点</span>
        </script>
		<script>
		    //定义全局变量
		    var agentlist = {};
		    layui.use(['layer','form','table'],function(){
		    	var layer = layui.layer,
		    	    form  = layui.form,
		    	    table = layui.table;
		    	
		    	layer.config({
					extend: 'MySkin/style.css'
				});
		    	
		    	
		    	table.render({
		    		elem:'#feedBackSet',
		    		url:'agent/feedBackSetting',
		    		method:'post',
		    		title:'代理返还比例设置',
		    		page : false,//分页
		    		id:'AllTable',
		    		cols:[[
		    			{field:'agent0',title:'一级代理返点',templet:'#agent0',style:'color:#d71345',edit: 'text'},
		    			{field:'agent1',title:'二级代理返点',templet:'#agent1',style:'color:#f47920',edit: 'text'},
		    			{field:'agent2',title:'三级代理返点',templet:'#agent2',style:'color:#f05b72',edit: 'text'},
		    			{field:'platformAgent',title:'平台获得返点',templet:'#platformAgent',style:'color:#d71345'}
		    			]],
		    			response:{
							statusCode : 200
						},
						parseData:function(res){
							return{
								"code":res.status,
								"msg":res.message,
								"count":res.count,
								"data":res.data
							};
						}
		    	});
		    	//监听单元格编辑
	              table.on('edit(feedBackSet)', function(obj){
	                var value = obj.value //得到修改后的值
	                ,data = obj.data //得到所在行所有键值
	                ,field = obj.field; //得到字段
	                
	                delete data["platformAgent"];
	                //检测
	                if (parseInt(data.agent0) + parseInt(data.agent1) + parseInt(data.agent2) > 100) {
	                	layer.msg("代理返还比例总和不能超过100%",{icon:2});
	                	return  false;
	                }
	                var loadingIndex = layer.msg('提交中..', {
		    			    icon: 16
		    			    ,shade: 0.3
		    			    ,time: false
		    			}); // 加载中动画遮罩层(1)
	                $.ajax({
		    			  type : 'POST',
		    			  url : 'game/ddzFeedBackSetting',
		    			  async : true,
		    			  dataType:'json',//期待返回数据 类型为json
		    			  contentType:'application/json',//发送类型为json
		    			  data : JSON.stringify(data),
		    			  success : function(resp) {
		    				  layer.close(loadingIndex); // 提交成功失败都需要关闭
		    				  if (resp.message === "success") {
		    					  layer.msg("操作成功",{icon:6});
		    				  }else{
		    					  layer.msg(resp.message,{icon:2});
		    				  }
		    				  table.reload('AllTable',{});
		    			  },error:function(){
		    				  layer.close(loadingIndex); // 提交成功失败都需要关闭
		    				  layer.msg("操作失败",{icon:6});
		    			  }
		    		  });
	              });
		    });
		</script>
</body>
</html>